home *** CD-ROM | disk | FTP | other *** search
/ HyperLib 1997 Winter - Disc 1 / HYPERLIB-1997-Winter-CD1.ISO.7z / HYPERLIB-1997-Winter-CD1.ISO / オンラインウェア / UTIL / ParamRAM guard.sit / ParamRAM guard / PRAM reset.c < prev    next >
C/C++ Source or Header  |  1994-01-13  |  3KB  |  85 lines

  1. /*
  2.  ***********************************************************************
  3.  *
  4.  *                                    PRAM Resetter
  5.  * This INIT resets the PRAM and extended PRAM from the saved settings,
  6.  * 'HEXA' resource named "Standard PRAM". See "PRAM save.cc" as to what PRAM
  7.  * is and how it's read into the resource.
  8.  *
  9.  * Be sure to make the present INIT resource locked (Look into the 
  10.  * "Set project type..." menu).
  11.  *
  12.  * There should be only one function within this file. Note, that when compiling
  13.  * a code resource, the compiler generates "call offset(A4)" type instructions
  14.  * when processing function calls. Beware, A4 generally is not set when the code 
  15.  * resource (especially INIT) is called. So, either set up A4 at the very beginning,
  16.  * or forget about functions. Note, that inlines are OK: they are just rolled
  17.  * out into the code, no call instruction is actually generated.
  18.  *
  19.  * Always make sure that the code is using standard LINK/UNLK sequence of
  20.  * commands to set up the frame, even if the code doesn't use temporary 
  21.  * (automatic, in C jargon) variables. Setting standard frame is necessary if the
  22.  * code uses any of the system/toolbox traps.
  23.  * (which strangely assume that A6 contains a valid frame pointer).
  24.  * Note, if the compiler does not produce standard LINK/UNLK sequence,
  25.  * inserting "asm { nop }" at the very beginning of the program usually helps. 
  26.  *
  27.  ***********************************************************************
  28.  */
  29.  
  30. #include "PRAM Resource.h"
  31.  
  32. //#include <OsUtils.h>
  33.  
  34.  
  35.                                 // This is
  36.                                 //        MOVE.L    (A7)+,D0        size -> lo word of d0
  37.                                 //        MOVEA.L      (A7)+,A0        where -> A0
  38.                                 //        _WriteXPRam
  39. static pascal void write_extended_PRAM
  40.     (const char * where, const short offset, const short size) =
  41. {0x201F, 0x205F, 0xA052};
  42.  
  43.  
  44.                                 // LEA.L     $01f8,a0
  45.                                 // MOVEQ      #$FF,d0
  46.                                 // _WriteParam
  47. static short WritePRAM(void) =
  48. {0x41F8, 0x01F8, 0x70FF, 0xA038};
  49.  
  50.  
  51.                                 // MOVE.L (a7),d0
  52. static int failed_init(const int failed_line) =
  53. { 0x2017 };
  54.  
  55.  
  56. #define assert_init(X) { if(X); else return failed_init(__LINE__); }
  57.  
  58. short main(void)
  59. {
  60.     struct PRAMSettings ** res_handle;
  61.  
  62.     asm { nop }                    // It forces generating "LINK A6" to set up a frame
  63.             
  64.     assert_init( (res_handle = 
  65.                     (struct PRAMSettings**)Get1NamedResource('HEXA',"¥pStandard PRAM")) 
  66.                     != nil );
  67.     assert_init( SizeResource((Handle)res_handle) == sizeof(struct PRAMSettings) );
  68.     assert_init( (unsigned char)((*res_handle)->PRAM).valid == 0xA8 );
  69.     
  70.     *(GetSysPPtr()) = (*res_handle)->PRAM;    // Copying PRAM settings into the Lo Globals
  71.     assert_init( WritePRAM() == noErr );
  72.     
  73.     write_extended_PRAM((char *)(*res_handle)->extended_PRAM.layout.parm1,
  74.                         (char *)(*res_handle)->extended_PRAM.layout.parm1 - (char *)(*res_handle)->extended_PRAM.body,
  75.                         sizeof((*res_handle)->extended_PRAM.layout.parm1));
  76.  
  77.     write_extended_PRAM((char *)(*res_handle)->extended_PRAM.layout.parm2,
  78.                         (char *)(*res_handle)->extended_PRAM.layout.parm2 - (char *)(*res_handle)->extended_PRAM.body,
  79.                         sizeof((*res_handle)->extended_PRAM.layout.parm2));
  80.  
  81.     return noErr;
  82. }
  83.  
  84.  
  85.